/*
 * @Author: Simon 1958058172@qq.com
 * @Date: 2025-08-13 14:42:45
 * @LastEditors: Simon 1958058172@qq.com
 * @LastEditTime: 2025-08-13 15:14:10
 * @FilePath: \java.1212\csdn\jihe\li08\work02.java
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
package csdn.jihe.li08;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

public class work02 {
    public static void main(String[] args) {

        Student s1=new Student("李霄",18,99);
        Student s2=new Student("李霄",168,989);
        Student s3=new Student("女霄",28,999);
        Student s4=new Student("tom",17,199);
System.out.println("自然排序--------------------------------------------");
        //自然排序
        Set<Student> tree1=new TreeSet<>();
        tree1.add(s1);
        tree1.add(s2);
        tree1.add(s3);
        tree1.add(s4);
        System.out.println(tree1);
//-----------------------------------------------------------------------
System.out.println("比较器排序------------------------------------------");
        //比较器排序
        Comparator<Student> comparator=new Comparator<Student>() {

        @Override
        public int compare(Student o1, Student o2) {
            int num;
            if(o1.getName()=="tom"){return -1;}
            //name降序
            num=o2.getName().compareTo(o1.getName());
            if(num==0){
                //age升序
                num=o1.getAge()-o2.getAge();
                if(num==0){
                    //score降序
                    num=o2.getScore()-o1.getScore();
                 }
            }
        return num;                
            }
        };
        Set<Student> tree2=new TreeSet<>(comparator);
        tree2.add(s1);
        tree2.add(s2);
        tree2.add(s3);
        tree2.add(s4);
        System.out.println(tree2);
        
    }
}
